/* 
 * File:   server.cpp
 * Author: Faraj
 * 
 * Created on May 6, 2013, 10:38 PM
 */

#include "server.h"

lib::server::server() {
}

lib::server::~server() {
}

MHD_Daemon* lib::server::get_daemon(){
    return _daemon;
}

string lib::server::get_addr(){
    return this->_addr;
}

bool lib::server::is_running(){
    return this->_running;
}

int lib::server::get_port(){
    return this->_port;
}

void lib::server::set_addr(string addr){
    this->_addr = addr;
}

void lib::server::set_port(int port){
    this->_port = port;
}

MHD_Daemon* lib::server::start(){
    common::log::trace("server.start");
    this->_daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, this->_port, NULL, NULL,
            this->_performer, NULL, MHD_OPTION_END);    
    this->_running = (NULL != this->_daemon);
}

void lib::server::stop(){
    common::log::trace("server.stop");
    if(this->_running){
        MHD_stop_daemon(this->_daemon);
    }
}

void lib::server::set_perform(web_connection_performer performer){
    this->_performer = performer;
}